import java.util.HashMap;
import java.util.Scanner;

public class StudentSytemDemo {
    // 模拟学生管理的数据库 使用 hashmap 实现 键值对得的方式
    private static HashMap<Long, Student> students = new HashMap<>();

    public static void main(String[] args) {
        while (true) {
            menu();
        }
    }
    // 菜单
    public static void menu() {
        System.out.println("-------------**喜来登**学生管理系统-----------------");
        System.out.println("-------------1.添加学生-----------------");
        System.out.println("-------------2.删除学生-----------------");
        System.out.println("-------------3.修改学生-----------------");
        System.out.println("-------------4.查询学生-----------------");
        System.out.println("-------------5.退出系统-----------------");
        System.out.println("----------------------------------------------");
        System.out.print("请输入功能号：");
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        StudentSytemDemo std  = new StudentSytemDemo();
        switch (choice) {
            case 1: std.addStudent(); break;
            case 2: std.delStudent(); break;
            case 3: std.updateStudent(); break;
            case 4: std.selectStudnt(); break;
            case 5:
                System.out.println("程序已经退出！"); System.exit(0);
            default:
                System.out.println("功能不存在！");
        }
    }

    // 添加学生信息
    public String addStudent() {
        // 1. 首先是查询学生信息是否存在 ， 存在的话就是提示  ---->  该学号已存在，请重新输入

        Scanner sc = new Scanner(System.in);
        System.out.print("请输入学号:");
        Long id = sc.nextLong();

        System.out.print("请输入姓名：");
        String name = sc.next();
        System.out.print("请输入年龄：");
        int age = sc.nextInt();
        System.out.print("请输入地址：");
        String adress = sc.next();
        Student st = new Student(id, name, age, adress);
        students.put(id, st);
        return "学生信息添加成功";
    }

    // 删除学生信息
    public String delStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入需要删除的学号：");
        Long id = sc.nextLong();
        Student student = students.get(id);
        if (student == null) {
            System.out.println("该学号不存在！");
            return "请重新选择选择功能！";
        }
        students.remove(id);
        return "学生信息删除成功！";
    }

    // 修改学生信息
    public String updateStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入需要修改学生信息的学号：");
        Long id = sc.nextLong();
        Student student = students.get(id);
        if (student == null) {
            System.out.println("该学号不存在");
            return "请重新选择选择功能！";
        }
        System.out.print("请输入修改的姓名:");
        String name = sc.next();
        System.out.print("请输入修改的年龄:");
        int age = sc.nextInt();
        System.out.print("请输入修改的地址:");
        String adress = sc.next();
        Student st = new Student(id, name, age, adress);
        students.put(id, st);
        return "学生信息修改成功！";
    }

    // 查询学生信息
    public void selectStudnt() {

        for (Long id : students.keySet()) {
            Student student = students.get(id);
            System.out.println("学号：" + student.getId());
            System.out.println("姓名：" + student.getName());
            System.out.println("年龄：" + student.getAge());
            System.out.println("地址：" + student.getAddress());
            System.out.println("-----------------------");
        }


    }

}